package utils

import (
	"errors"
)

// 业务层错误码列表
const (
	Success    = 0
	Error      = 500
	NotFound   = 400
	BadRequest = 401

	// 权限校验
	LoginTokenNotFound    = 10001
	LoginTokenPaserFailed = 10002
	LoginTokenExpired     = 10003
	LoginTokenAuthFailed  = 10004
	NoLogin               = 10005
	NoProjectPermission   = 10006
	// 参数校验
	JsonRequired    = 20001
	ParamAbsent     = 20002
	ParamTypeError  = 20003
	ParamValueError = 20004
	ParamParseError = 20005
	// 文件相关
	FileDirError  = 30001
	FileOpenError = 30002
	//etcd操作
	EtcdEditError    = 40001
	EtcdDeleteError  = 40002
	EtcdGetError     = 40003
	EtcdUnknownError = 40004
	//db操作相关
	DBEditError    = 50001
	DBConnectError = 50002
	DBGetInfoError = 50003
	//Notify相关
	NotifyFail = 60001
	// 特定错误
	NoDataMatched = 90001
)

// 基础的错误信息
var MsgFlags = map[int]string{
	Success:               "ok",
	Error:                 "fail",
	BadRequest:            "request err",
	NotFound:              "not found",
	LoginTokenNotFound:    "Token not found",
	LoginTokenPaserFailed: "Token parse fail",
	LoginTokenExpired:     "Token expired",
	LoginTokenAuthFailed:  "Token authorize fail",
	NoLogin:               "no login",
	NoProjectPermission:   "no project permission",
	// 参数校验
	JsonRequired:    "json payload required",
	ParamAbsent:     "lack of parameter",
	ParamTypeError:  "parameter type error",
	ParamValueError: "parameter value not support",
	ParamParseError: "parameter parse err",
	// 文件相关
	FileDirError:  "file dir err",
	FileOpenError: "file open err",
	// 特定错误
	NoDataMatched: "no data matched",
	//db操作
	DBEditError:    "db edit err",
	DBConnectError: "db connect err",
	DBGetInfoError: "get db info err",
	//etcd操作
	EtcdEditError:    "etcd edit error",
	EtcdDeleteError:  "etcd delete error",
	EtcdGetError:     "etcd select error",
	EtcdUnknownError: "etcd unknown error",
}

var (
	ERR_LOCK_ALREADY_REQUIRED = errors.New("锁已被占用")
	GigaBytes                 = 1024 * 1024 * 1024
)

var (
	KeyUserName         = "username"
	KeyUid              = "uid"
	PrefixParams        = "Prefix_Params"
	PrefixFiles         = "Prefix_Files"
	PrefixFilesSize     = "Prefix_Files_Size"
	PrefixGinController = "Prefix_Gin_Controller"
	PrefixResponse      = "Prefix_Response"
)

type DetailResponse struct {
	TraceId string      `json:"ntes-trace-id"`
	Code    int         `json:"code"`
	Message string      `json:"msg"`
	Detail  interface{} `json:"detail,omitempty"`
}

type Auth struct {
	Name    string
	Project string
	Token   string
	Role    string
}
